package com.china08.yxyapi.api.manage.stu.mystudy.homework.workinfo;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.es.ElasticYxyYxyQuesResource;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.es.ElasticYxyYxyQuesResourceRespository;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;

/**
 * 查询作业试题类 2017年3月13日11:14:25
 * 
 * @author lys
 *
 */
// @Api(tags = { "v290", "查询作业试题类" })
@CrossOrigin
@RestController
public class HomeWorkQuestionController extends YxyApiBaseController {

    @Autowired
    private ElasticYxyYxyQuesResourceRespository elasticYxyYxyQuesResourceRespository;

    /**
     * 查询作业详细信息方法 2017年3月13日11:14:47
     * 
     * @param request
     * @param response
     * @param reqModel
     *            试题的ID
     * @return
     * @throws IOException
     * @throws JsonMappingException
     * @throws JsonParseException
     */
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/stu/mystudy/homework/workinfo/homeworkquestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(@RequestBody ReqModel reqModel)
            throws JsonParseException, JsonMappingException, IOException {
        RespModel model = new RespModel();
        Assert.hasText(reqModel.questionID, "试题ID不能为空");
        ElasticYxyYxyQuesResource elasticYxyYxyQuesResource = elasticYxyYxyQuesResourceRespository
                .findById(reqModel.questionID);
        Assert.notNull(elasticYxyYxyQuesResource, "查询试题信息失败");
        model.difficultyLevel = elasticYxyYxyQuesResource.getDifficultyLevel();
        model.id = elasticYxyYxyQuesResource.getId();
        model.knowledgeTexts = elasticYxyYxyQuesResource.getKnowledgeTexts();
        model.quesBody = elasticYxyYxyQuesResource.getQuesBody();
        model.questionType = elasticYxyYxyQuesResource.getQuestionType();
        return model;

    }

    protected static class ReqModel extends YxyApiReqModel {
        /*
         * 试题的ID
         */
        public String questionID;

    }

    protected static class RespModel extends YxyApiRespModel {
        // 试题id
        public String id;
        // 试题的难度等级
        public String difficultyLevel;
        // 试题的知识点名称
        public List<String> knowledgeTexts;
        // 试题类型
        public String questionType;
        //
        public Object quesBody;
    }
}
